//
//  ShareImageView.m
//  Cat
//
//  Created by lushitong on 2018/12/25.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "ShareImageView.h"

@interface ShareImageView()
@property (nonatomic, strong) UIButton *shareButton;
@property (nonatomic, strong) UILabel *shareTitleLabel;
@property (nonatomic, copy) void(^clickShareBlock)(void);

@end
@implementation ShareImageView

+ (CGSize)getSize {
	CGFloat width = (ScreenWidth - kQKFitModuleDecimal(17) * 2 - kQKFitModuleDecimal(24) * 4) / 5;
	return CGSizeMake(width, width + kQKFitModuleDecimal(18));
}

- (void)setShareImageName:(NSString *)imageName andShareTitle:(NSString *)shareTitle {
	[self.shareButton setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
	self.shareTitleLabel.text = shareTitle;
}

- (void)clickShareButton:(void (^)(void))block {
	self.clickShareBlock = block;
}

- (instancetype)initWithFrame:(CGRect)frame {
	self = [super initWithFrame:frame];
	if (self) {
		[self loadAllSubView];
	}
	return self;
}

- (void)shareButtonAction {
	if (self.clickShareBlock) {
		self.clickShareBlock();
	}
}

- (void)loadAllSubView {
	CGFloat width = (ScreenWidth - kQKFitModuleDecimal(17) * 2 - kQKFitModuleDecimal(24) * 4) / 5;
	
	[self addSubviews:@[self.shareButton,self.shareTitleLabel]];
	[self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake(width, width));
		make.top.equalTo(self.mas_top);
		make.left.and.right.equalTo(self);
	}];
	
	[self.shareTitleLabel  mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.shareButton.mas_centerX);
		make.bottom.equalTo(self.mas_bottom);
	}];
}

#pragma mark----- lazy init -----

- (UIButton *)shareButton {
	if (!_shareButton) {
		_shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
		[_shareButton addTarget:self action:@selector(shareButtonAction) forControlEvents:UIControlEventTouchUpInside];
	}
	return _shareButton;
}

- (UILabel *)shareTitleLabel {
	if (!_shareTitleLabel) {
		_shareTitleLabel = [UILabel labelWithFont:[UIFont systemFontOfSize:kQKFitFont(10)] textColor:COLOR_WITH_HEX(0x4A4A4A)];
	}
	return _shareTitleLabel;
}


@end
